/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.demo.widget.meis.slice;

import com.demo.widget.ResourceTable;
import com.meis.widget.corners.CornersGifView;
import com.meis.widget.utils.PixelUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Slider;
import ohos.agp.components.Text;

import java.math.BigDecimal;

public class MeiCornersGifAbilitySlice extends AbilitySlice {
    CornersGifView test;
    Slider mSeekBar01, mSeekBar02, mSeekBar03, mSeekBar04;
    Text mTextView01, mTextView02, mTextView03, mTextView04;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_mei_corners_gif);
        PixelUtil.initContext(getContext());
        initView();
    }

    private void setSlider(Text textView,Slider slider,int  type) {
        slider.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i, boolean b) {
                switch (type){
                    case 0:
                        textView.setText("左上圆角：" + i);
                        test.setLeftTopCorner(BigDecimal.valueOf(i).floatValue());
                        break;
                    case 1:
                        textView.setText("左下圆角：" + i);
                        test.setLeftBottomCorner(BigDecimal.valueOf(i).floatValue());
                        break;
                    case 2:
                        textView.setText("右上圆角：" + i);
                        test.setRightTopCorner(BigDecimal.valueOf(i).floatValue());
                        break;
                    case 3:
                        textView.setText("右下圆角：" + i);
                        test.setRightBottomCorner(BigDecimal.valueOf(i).floatValue());
                        break;
                }

            }

            @Override
            public void onTouchStart(Slider slider) {
            }

            @Override
            public void onTouchEnd(Slider slider) {
            }
        });

    }

    private void initView() {
        test = (CornersGifView) findComponentById(ResourceTable.Id_test);
        mSeekBar01 = (Slider)findComponentById(ResourceTable.Id_seek_01);
        mSeekBar02 = (Slider)findComponentById(ResourceTable.Id_seek_02);
        mSeekBar03 = (Slider)findComponentById(ResourceTable.Id_seek_03);
        mSeekBar04 = (Slider)findComponentById(ResourceTable.Id_seek_04);
        mTextView01 = (Text)findComponentById(ResourceTable.Id_tv_01);
        mTextView02 = (Text)findComponentById(ResourceTable.Id_tv_02);
        mTextView03 = (Text)findComponentById(ResourceTable.Id_tv_03);
        mTextView04 = (Text)findComponentById(ResourceTable.Id_tv_04);
        setSlider(mTextView01,mSeekBar01,0);
        setSlider(mTextView02,mSeekBar02,1);
        setSlider(mTextView03,mSeekBar03,2);
        setSlider(mTextView04,mSeekBar04,3);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
